const express  = require('express');
const db = require('../db/db');
const config = require('../config');
const jwt = require('jsonwebtoken');
//路由
const router = express.Router();

//获取全部房间信息
router.get('/all',(req,res)=>{
    const sql = 'select * from room'
    db.query(sql,(err,results)=>{
        if(err) return res.send({status:500,message:"服务器错误"})
        console.log(results)
        if(results.length > 0){
            return res.send({status:200,data:results,message:"查询成功"})
        }
    })
})

//查询房型
router.get('/rtype',(req,res)=>{
    const {rtype} = req.query
    console.log(req)
    const sql = 'select * from room where rtype = ?'
    db.query(sql,[rtype],(err,results)=>{
        if(err) return res.send({status:500,message:"服务器错误"})
        if(results.length > 0){
            return res.send({status:200,data:results,message:"查询成功"})
        }
    })
})

//预定房型
router.post('/order',(req,res)=>{
    const { userId} = req
    res.send({userId})
})
module.exports = router